package datastruct.bitset;

import java.util.BitSet;

public class RepeatNumberArray {

	public static void main(String[] args) {
		//int[] ary = {1,3,5,7,11,13,5,3};
		int[] ary = {1,3,5,7,11,13,19};
		System.out.println(new RepeatNumberArray().isRepeatNumberArray(ary));

	}
	
	/**
	 * 判断正整数数组是否有重复元素
	 * @param ary
	 * @return true重复数字数组；false没有重复数字的数组
	 */
	public boolean isRepeatNumberArray(int[] ary) {
		if(ary == null || ary.length <= 1) {
			return false;
		}
		BitSet bitset = new BitSet(Integer.MAX_VALUE);
		
		for(int i=0;i<ary.length;i++) {
			if(bitset.get(ary[i])) {
				System.out.println(ary[i]);
				return true;
			}else {
				bitset.set(ary[i], true);
			}
		}
		return false;
	}

}
